<?php

//some code to connect to the dbase

$username="root";
$password="dwd4zx6p";
$database="docdiscuss";

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

?>

<html>
<head>
<title>Upload file</title>
</head>

<body>
<?php

$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['docFile']['name']); 
$name = basename($_FILES['docFile']['name']);

if(move_uploaded_file($_FILES['docFile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['docFile']['name']). 
    " has been uploaded.";

$query = "INSERT INTO documents (name, filename, status) VALUES ('$_POST[docName]','$name','0')";
mysql_query($query);
$id = mysql_insert_id();

$targetpath = "jobs/" . $id;

//create jobs directory
if(!mkdir($targetpath, 0777)) {
	die("Directory creation fail!");
}

chmod($targetpath, 0777);

//copy file over
$original = "uploads/" . $name;
$new = $targetpath . "/" . $name;

if(!copy($original, $new)) {
	die("File copy fail!");
}

} else{
    echo "There was an error uploading the file, please try again!";
}

?>

<br/>
<br/>
<a href="index.php">Back</a>

</body>
</html>
